import java.io.IOException;
import java.sql.*;

public class fang {
    public static void main(String[] args) throws ClassNotFoundException{


        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","Fang060825");
            String sql = "select * from demo";
            PreparedStatement ps = conn.prepareStatement(sql);//预处理SQL语句；
            ResultSet rs = ps.executeQuery();//执行SQL语句；
            while(rs.next()) {
                int id = rs.getInt("id");
                String name = rs.getString("name");
                int pass = rs.getInt("pass");
                System.out.println("id:"+id+",name:"+name+",passs:"+pass);
            }
        }
        catch(SQLException e){
            System.out.println(e);
        }
        catch(ClassNotFoundException e){
            System.out.println(e);
        }
    }
}
